package com.tangqiao;

import java.net.URLEncoder;

public class BNUEncoder {
	public static String encode(String info, String time) {
		String ret="";
		String s2 = time;
		String s1 = info;
		int len1, len2;
		len1 = info.length();
		len2 = time.length();
		if (len2 != 8) {
			System.out.println("ERROR: time format error.");
			return "";
		}
		int i;
		int esi = 7;
		int edx = 0;
		char b1, b2;
		for (i = 0; i < len1; ++i) {
			char c1 = s1.charAt(i);
			char c2 = s2.charAt(esi);
			char v = (char)((byte)c1 ^ (byte)c2);
			char to1 = (char)(((byte)v & 0x0F) + 0x36);
			char to2 = (char)(((byte)v >> 4) + 0x63);
			edx = esi;
			edx &= 0x80000001;
			if (edx < 0) {
				edx--;
				edx |= 0xFFFFFFFE;
				edx++;
			}
			if (edx != 0)
				b1 = to1;
			else
				b1 = to2;
			if (edx == 0)
				b2 = to1;
			else
				b2 = to2;
			esi--;
			if (esi < 0)
				esi = 7;
			ret += (char)b1;
			ret += (char)b2;
		}
		return URLEncoder.encode(ret);
	}
	public static void main(String[] args) {
		System.out.println(BNUEncoder.encode("19841008", "21067643"));
		System.out.println(BNUEncoder.encode("00:11:25:48:88:67", "21068758"));
	}
}
